home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / ACORNUSERS / CBSA / EDUCATION / SAVER / cc / WimpIcon < prev    next >
Text File  |  1997-12-26  |  2KB  |  117 lines

  1.  
  2. //-----------------------------------
  3. //             WimpIcon.c
  4. //-----------------------------------
  5.  
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <os.h>
  9. #include <trap.h>
  10. #include "WimpError.h"
  11. #include "EventData.h"
  12. #include "WimpIcon.h"
  13.  
  14. WimpIcon::WimpIcon(WimpIcon &icon, int iflags, int window,
  15.                    int priority, int x0, int y0, int x1, int y1)
  16. {
  17.   int r[10];
  18.   os_error *e;
  19.   indirect = icon.indirect;
  20.   flags = iflags;
  21.   handle = window;      // Provisoire
  22.   xmin = x0;
  23.   ymin = y0;
  24.   xmax = x1;
  25.   ymax = y1;
  26.   r[0] = priority;
  27.   r[1] = (int)&handle;
  28.   if ((e = os_swi(Wimp_CreateIcon, r)) != NULL) throw(e);
  29.   handle = r[0];
  30.   window_handle = window; 
  31. }
  32.  
  33. WimpIcon::WimpIcon(char *spritename, int iflags, int window, int priority,
  34.                    int x0, int y0, int x1, int y1)
  35. {
  36.   int r[10];
  37.   os_error *e;
  38.   if (iflags & INDIRECT)
  39.   {
  40.     indirect_sprite.sprite_name = new char[strlen(spritename)+1];
  41.     strcpy(indirect_sprite.sprite_name, spritename);
  42.     indirect_sprite.sprite_area = (int *)1;
  43.     indirect_sprite.isname = 1;
  44.   }
  45.   else strncpy(sprite_name, spritename, 12);
  46.   flags = iflags;
  47.   window_handle = window;
  48.   handle = window;        // Provisoire
  49.   xmin = x0;
  50.   ymin = y0;
  51.   xmax = x1;
  52.   ymax = y1;
  53.   r[0] = priority;
  54.   r[1] = (int) &handle;
  55.   if ((e = os_swi(Wimp_CreateIcon, r)) != NULL) throw(e);
  56.   handle = r[0];  
  57. }
  58.  
  59. void WimpIcon::Delete()
  60. {
  61.   int r[10];
  62.   os_error *e;
  63.   int b[2];
  64.   b[0] = window_handle;
  65.   if (b[0] < -1) b[0] = -2;
  66.   b[1] = handle;
  67.   r[1] = (int) b;
  68.   if ((e = os_swi(Wimp_DeleteIcon, r)) != NULL) throw(e);  
  69. }
  70.  
  71. WimpIcon::~WimpIcon()
  72. {
  73.   if (flags & INDIRECT) delete indirect_sprite.sprite_name;
  74. }
  75.  
  76. WimpIcon::operator int()
  77. {
  78.   return handle;
  79. }
  80.  
  81. void WimpIcon::GetState()
  82. {
  83.   os_error *e;
  84.   int r[10];
  85.   r[1] = (int) this;
  86.   e = os_swi(Wimp_GetIconState,r);
  87. }
  88.  
  89. void WimpIcon::drag()
  90. {
  91.   os_error *e;
  92.   int r[10];
  93.   int ox,oy;
  94.   static Window_Info w;
  95.   static int DragData[14]; 
  96.   
  97.   w.handle = window_handle;
  98.   r[1] = (int) &w;
  99.   e = os_swi(Wimp_GetWindowState,r);
  100.   ox = w.xmin - w.scrollx;
  101.   oy = w.ymax - w.scrolly;
  102.   GetState();
  103.   DragData[0] = window_handle;
  104.   DragData[1] = 5;
  105.   DragData[2] = ox + xmin;
  106.   DragData[3] = oy + ymin;
  107.   DragData[4] = ox + xmax;
  108.   DragData[5] = oy + ymax;
  109.   DragData[6] = 0;
  110.   DragData[7] = 0;
  111.   DragData[8] = 0x7FFFFFFF;
  112.   DragData[9] = 0x7FFFFFFF;
  113.   r[1] = (int) DragData;
  114.   e = os_swi(Wimp_DragBox,r);
  115. }
  116.  
  117.